package com.lanchetech.merchant.service.impl;


import com.lanchetech.bean.vo.jst.UploadOrderVO;
import com.lanchetech.common.constants.JstConstant;
import com.lanchetech.common.util.HttpUtil;
import com.lanchetech.common.util.SignUtil;
import com.lanchetech.merchant.service.JstService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class JstServiceImpl implements JstService {


    private static String uploadOrderInfo() {

        Map<String, String> params = new HashMap<>();
        params.put("app_key", JstConstant.APP_KEY);
        params.put("access_token", JstConstant.ACCESS_TOKEN);
        params.put("timestamp", String.valueOf(System.currentTimeMillis() / 1000));
        params.put("charset", JstConstant.CHARSET);
        params.put("version", "2");
        params.put("sign", SignUtil.getSign(JstConstant.APP_SECRET, params));
//        UploadOrderVO orderInfo = getOrderInfo();
//        String biz = JSON.toJSONString(Collections.singletonList(orderInfo));

        String biz = "[{\"ext_datas\":{\"CompanyName\":\"\",\"DoorPlate\":\"\"},\"lc_id\":\"\",\"question_desc\":\"\",\"receiver_email\":\"\",\"receiver_city\":\"郑州\",\"invoice_title\":\"\",\"freight\":4.0,\"remark\":\"卖家备注\",\"is_cod\":false,\"receiver_state\":\"河南省\",\"receiver_zip\":\"\",\"send_date\":\"\",\"buyer_tax_no\":\"\",\"so_id\":\"20211110\",\"receiver_name\":\"杰森\",\"currency\":\"\",\"invoice_type\":\"\",\"receiver_country\":\"\",\"creator\":\"\",\"shipment\":\"\",\"shop_status\":\"WAIT_SELLER_SEND_GOODS\",\"buyer_message\":\"买家留言\",\"receiver_district\":\"经济技术开发区\",\"receiver_town\":\"aaa街道\",\"pay_amount\":706.0,\"pay\":{\"outer_pay_id\":\"155775985878733471\",\"pay_date\":\"2019-12-1616:35:28\",\"amount\":706.0,\"buyer_account\":\"38\",\"payment\":\"微信\",\"seller_account\":\"未知\"},\"receiver_mobile\":\"18626862362\",\"labels\":\"\",\"seller_flag\":0,\"finance_data\":{\"other_income\":0,\"opaque_bagging_fee\":0,\"product_tax\":0,\"other_expense\":0,\"platform_commission\":0,\"transaction_fee\":0,\"rebate_fee\":0,\"transition_fee\":0,\"voucher_from_seller\":0,\"shipping_tax\":0},\"shop_id\":10193862,\"order_date\":\"2019-12-15 18:14:26\",\"node\":\"\",\"shop_buyer_id\":\"561328\",\"wms_co_id\":0,\"shop_modified\":\"2019-12-16 15:24:18\",\"receiver_address\":\"啦啦啦哈哈哈哈哈哈哈\",\"logistics_company\":\"\",\"creator_name\":\"\",\"invoice\":{\"userAddress\":\"\",\"bank\":\"\",\"address\":\"\",\"phone\":\"\",\"userPhone\":\"\",\"userName\":\"\",\"account\":\"\",\"email\":\"\"},\"receiver_phone\":\"18626862362\",\"l_id\":\"\",\"items\":[{\"i_id\":\"\",\"amount\":223.0,\"refund_status\":\"\",\"batch_id\":\"\",\"sku_id\":\"s111001\",\"remark\":\"\",\"pic\":\"\",\"shop_sku_id\":\"438\",\"produced_date\":\"\",\"properties_value\":\"SKUA1\",\"is_gift\":true,\"qty\":1,\"base_price\":223.0,\"name\":\"SKUA1\",\"outer_oi_id\":\"8_438\"}],\"card\":{\"name\":\"11\",\"card_id\":\"11\"}}]";
        params.put("biz", biz);

        return HttpUtil.sendPost(JstConstant.DOMAIN_URL + JstConstant.ORDERS_UPLOAD, params);

    }

    private static String getAccessToken() {
        Map<String, String> params = new HashMap<>();
        params.put("app_key", JstConstant.APP_KEY);
        params.put("timestamp", String.valueOf(System.currentTimeMillis() / 1000));
        params.put("grant_type", "authorization_code");
        params.put("charset", JstConstant.CHARSET);
        params.put("version", "2");
        params.put("code", "");
        params.put("sign", SignUtil.getSign(JstConstant.APP_SECRET, params));
        return HttpUtil.sendPost("https://openapi.jushuitan.com/openWeb/auth/accessToken", params);
    }

    private static UploadOrderVO getOrderInfo() {
        UploadOrderVO vo = new UploadOrderVO();
        vo.setReceiver_name("张三");
        vo.setSo_id("318201293");

        return vo;
    }


    public static void main(String[] args) {
        System.out.println(uploadOrderInfo());
        System.out.println(getAccessToken());
    }


}